import { connect } from 'dva';
import debounce from 'lodash/debounce';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';

import { getColumnIntoWidth } from '@/src/utils/utils';

import styles from './index.less';

let inputOnchange; // 标记 虚拟文本
@connect(({ qualificationManagementPlanMaintenanceM, loading, globalM }) => ({
  qualificationManagementPlanMaintenanceM,
  loading,
  globalM,
}))
class BaseInfoProduct extends PureComponent {
  // props默认值
  static defaultProps = {
    onRef: () => {}, // 本组件的引用
    setStatus: () => {}, // 新增编辑查看用于抛出弹窗组件参数
    changePage: () => {}, // 新增编辑查看用于抛出显示框架还是弹窗参数
  };

  // 穿透工作台基本信息资产Tab
  constructor(props) {
    super(props);
    this.state = {
      dataSource: [],
      columns: [],
    };
    this.getInfoDebounce = debounce(this.getInfoDebounce, 500);
  }

  getProductInfo = () => {};

  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
    this.getProductInfo();
  }

  /**
   * 操作列
   * @param e {React.BaseSyntheticEvent}
   * @param record {*}
   */
  handleOperate = (e, record) => {
    e.preventDefault();
    const { type } = e.target.dataset;
    // 查看
    if (type === '1') {
    }
    // 编辑
    if (type === '2') {
    }
    // 删除
    if (type === '3') {
    }
  };

  // 扩展column
  changeColumns = (columns) => {
    if (columns.length === 0) return [];
    const needColumn = columns;
    needColumn.map((x) => {});
    return needColumn;
  };

  // 执行父组件获取信息getAssetInfo
  getInfoDebounce = (searchVal) => {
    this.getProductInfo(searchVal);
  };

  // 改变搜索值
  onChange = (e) => {
    const searchVal = e.target?.value;
    this.getInfoDebounce(searchVal);
  };

  render() {
    const { columns, dataSource } = this.state;
    const widthColumn = getColumnIntoWidth(columns, dataSource); // 自动计算width并插入
    const newColumns = this.changeColumns(widthColumn);
    return <div className={styles.baseInfoProduct}>{/* BaseInfoProduct */}</div>;
  }
}
BaseInfoProduct.propTypes = {
  onRef: PropTypes.func, // 本组件的引用
  // eslint-disable-next-line react/no-unused-prop-types
  setStatus: PropTypes.func, // 新增编辑查看用于抛出弹窗组件参数
  // eslint-disable-next-line react/no-unused-prop-types
  changePage: PropTypes.func, // 新增编辑查看用于抛出显示框架还是弹窗参数
};
export default BaseInfoProduct;
